package cn.hjh.controller;

import cn.hjh.pojo.Users;
import cn.hjh.service.UsersService;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/users")
public class UsersController {

    @Resource
    private UsersService usersServiceImpl;

    @RequestMapping("/save")
    public String save(){
        return "regit";
    }

    @RequestMapping("/addsave")
    public String add(Users users, HttpServletRequest request){
        users.setName(request.getParameter("name"));
        users.setPassword(request.getParameter("password"));
//        users.setId(users.getId());
        usersServiceImpl.save(users);
        return "redirect:/users/list";

    }

    @RequestMapping("/list")
    public String denglu(){
        return "list";
    }

    @RequestMapping("/denglutest")
    public String list(@RequestParam String name,@RequestParam String password){

        Users users = usersServiceImpl.denglu(name,password);

        if(users!=null){
            return "list";
        }

        return "list";
    }
}
